home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Freeware / Griffith 0.9.8 / griffith-0.9.8-win32.exe / {app} / lib / plugins / movie / PluginMovieFDb.py < prev    next >
Text File  |  2008-11-17  |  6KB  |  171 lines

  1. # -*- coding: utf-8 -*-
  2.  
  3. __revision__ = '$Id: PluginMovieFDb.py 1040 2008-11-15 21:13:49Z mikej06 $'
  4.  
  5. # Copyright (c) 2006-2007 Piotr Ozarowski
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU Library General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  20.  
  21. # You may use and distribute this software under the terms of the
  22. # GNU General Public License, version 2 or later
  23.  
  24. import gutils
  25. import movie
  26. import string
  27. import re
  28.  
  29. plugin_name        = 'FDb'
  30. plugin_description    = 'Internetowa baza filmowa'
  31. plugin_url        = 'fdb.pl'
  32. plugin_language        = _('Polish')
  33. plugin_author        = 'Piotr O┼╝arowski'
  34. plugin_author_email    = '<ozarow+griffith@gmail.com>'
  35. plugin_version        = '1.8'
  36.  
  37. class Plugin(movie.Movie):
  38.     TRAILER_PATTERN = re.compile('\s*<a\shref=[\'"](.*?)["\'].*?>\(zobacz\szwiastun\)</a>')
  39.     
  40.     def __init__(self, movie_id):
  41.         from md5 import md5
  42.         self.movie_id = md5(movie_id).hexdigest()
  43.         self.encode   = 'utf-8'
  44.         if string.find(movie_id, 'http://') != -1:
  45.             self.url = str(movie_id)
  46.         else:
  47.             self.url = "http://fdb.pl/%s" % str(movie_id)
  48.  
  49.     def get_image(self):
  50.         self.image_url = gutils.trim(self.page, 'class="moviePosterTable"', '</td>');
  51.         self.image_url = gutils.trim(self.image_url,' src="',"\"\n")
  52.         if self.image_url.endswith('no_picture.png'):
  53.             self.image_url = ''
  54.         else:
  55.             self.image_url = "http://fdb.pl%s" % self.image_url
  56.  
  57.     def get_o_title(self):
  58.         self.o_title = gutils.trim(self.page, '<h2>', '</h2>')
  59.         self.o_title = gutils.strip_tags(self.o_title)
  60.         if self.o_title == '':
  61.             self.o_title = self.get_title(True)
  62.  
  63.     def get_title(self, extra=False):
  64.         data = gutils.trim(self.page,'<title>', '</title>')
  65.         tmp = string.find(data, '(')
  66.         if tmp != -1:
  67.             data = data[:tmp]
  68.         if extra is False:
  69.             self.title = data
  70.         else:
  71.             return data
  72.  
  73.     def get_director(self):
  74.         self.director = ''
  75.         elements = gutils.trim(self.page,'>Re┼╝yseria</div>','<br />')
  76.         elements = string.split(elements, '<div>')
  77.         if elements[0] != '':
  78.             for element in elements:
  79.                 element = gutils.trim(element, '>', '</a')
  80.                 if element != '':
  81.                     self.director += ', ' + element
  82.             self.director = string.replace(self.director[2:], ',    (wi─Öcej)', '')
  83.  
  84.     def get_plot(self):
  85.         self.plot = gutils.trim(self.page,'>Opis filmu:</div>','</div>')
  86.         self.plot = self.TRAILER_PATTERN.sub('', self.plot)
  87.  
  88.     def get_year(self):
  89.         self.year = gutils.trim(self.page,' class="movieYear">(', ')</span>')
  90.  
  91.     def get_runtime(self):
  92.         self.runtime = gutils.trim(self.page,">Czas trwania:</span>\n        ",' min')
  93.  
  94.     def get_genre(self):
  95.         self.genre = gutils.trim(self.page,'>Gatunek:</span>','</div>')
  96.         self.genre = string.replace(self.genre, '   ', '')
  97.  
  98.     def get_cast(self):
  99.         self.cast = gutils.trim(self.page,'>Obsada:</div>', """<tr>
  100.             <td colspan""")
  101.         if self.cast != '':
  102.             self.cast = self.cast.replace('....',_(' as '))
  103.             self.cast = self.cast.replace('  ', '')
  104.             self.cast = self.cast.replace("\n", '')
  105.             self.cast = self.cast.replace('</tr>', "\n")
  106.  
  107.     def get_classification(self):
  108.         self.classification = gutils.trim(self.page,">Od lat:</span>\n","\n")
  109.  
  110.     def get_studio(self):
  111.         self.studio = ''
  112.  
  113.     def get_o_site(self):
  114.         self.o_site = ''
  115.  
  116.     def get_site(self):
  117.         self.site = self.url
  118.  
  119.     def get_trailer(self):
  120.         trailer_url = self.TRAILER_PATTERN.findall(self.page)
  121.         if trailer_url:
  122.             self.trailer = trailer_url[0]
  123.  
  124.     def get_country(self):
  125.         self.country = gutils.trim(self.page,">Kraj:</span>\n",'</div>')
  126.         self.country = string.replace(self.country, "   ", '')
  127.  
  128.     def get_rating(self):
  129.         self.rating = gutils.trim(self.page, '>Ocena:</span>','/10</span>')
  130.         self.rating = gutils.after(self.rating, 'bold">')
  131.         if self.rating:
  132.             self.rating = str(float(gutils.clean(self.rating)))
  133.  
  134. class SearchPlugin(movie.SearchMovie):
  135.     def __init__(self):
  136.         self.encode = 'utf-8'
  137.         self.original_url_search    = 'http://fdb.pl/szukaj.php?t=f&s='
  138.         self.translated_url_search    = 'http://fdb.pl/szukaj.php?t=f&s='
  139.  
  140.     def search(self,parent_window):
  141.         self.open_search(parent_window)
  142.         tmp = string.find(self.page,'<div>Wyniki wyszukiwania dla')
  143.         if tmp == -1:        # already a movie page
  144.             self.page = ''
  145.         else:            # multiple matches
  146.             self.page = gutils.before(self.page[tmp:],'<div id="mapaSerwisu">');
  147.         return self.page
  148.  
  149.     def get_searches(self):
  150.         if self.page == '':    # movie page already
  151.             self.number_results = 1
  152.             self.ids.append(self.url)
  153.             self.titles.append(self.title)
  154.         else:            # multiple matches
  155.             elements = string.split(self.page,'<div class="searchItem">')
  156.             if len(elements)>0:
  157.                 for element in elements:
  158.                     tmpId = gutils.trim(element, '<a href="', '"')
  159.                     if tmpId.endswith('dodajNowy.php'):
  160.                         continue
  161.                     self.ids.append(tmpId)
  162.                     element = gutils.strip_tags(
  163.                         gutils.trim(element, '">', '</div>'))
  164.                     element = element.replace("\n", '')
  165.                     element = element.replace('   ', '')
  166.                     element = element.replace('aka ', ' aka ')
  167.                     element = element.replace(' - Oryginalny', '')
  168.                     self.titles.append(element)
  169.             else:
  170.                 self.number_results = 0
  171.